package com.david.func_test.viewpager

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.david.func_test.R

class PagerFragment(var index: Int, var changeFragment: OnChangeFragment? = null) : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_viewpager, container, false)
        val title = view.findViewById<TextView>(R.id.title)
            title.text = "$index pagepagepagepagepagepagepagepagepagepagepagepagepagepagepagepagepagepagepagepage"
        view.findViewById<ImageView>(R.id.image).setImageResource(R.mipmap.img_map)
        if (index == 2) {
            title.setOnClickListener {
                changeFragment?.changeFragment()
//                (activity as FragmentActivity).supportFragmentManager.beginTransaction().replace(R.id.viewpager, NewFragment())
            }
        }
        return view
    }
}